const mongoose = require('mongoose');
const userSchema = mongoose.Schema({
    _id: mongoose.Schema.Types.ObjectId,
    username: { type: String, required: true },
    phone: { type: Number, required: true, unique: true, match: /^(0|86|17951)?(13[0-9]|15[012356789]|166|17[3678]|18[0-9]|14[57])[0-9]{8}$/ },
    address: { type: String, required: true },
    //email: { type: String,unique: true,default: '', match: /[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/ },
    password: { type: String, required: true }
}, {
        timestamps: {
            createdAt: 'created',
            updatedAt: 'updated'
        }/*,
        collection:'users'存储在该集合中*/
    })

module.exports = mongoose.model("User", userSchema);